<template>
	<div class="npad-application-container">
		<header class="npad-application-header" >
			<div class="npad-application-header-icon icon" :class="setting.icon"></div>
			<div class="npad-application-header-title">{{setting.title}}</div>
			<div class="npad-application-header-control">
				<div class="npad-application-control-close" @click="onClose()"></div>
			</div>
			
		</header>
		<div class="npad-application-body" :ref="'application_' + setting.id">
			<keep-alive><component :is="data.subComponent" ></component></keep-alive>
		</div>
	</div>
</template>
<script setup>
	import $store from '../store/index'
	import { defineProps } from 'vue';
	import { reactive, onMounted, onBeforeMount ,defineAsyncComponent,markRaw} from 'vue';
	import loadingComponent from './loadingComponent.vue'
	import errorComponent from './errorComponent.vue'
	const setting = defineProps({
		title:{
			type:String,
			default:""
		},
		id:String,
		icon:{
			type:String,
			default:"help"
		},
		page:{
			type:String,
			default:"calculator"
		},
		focus:Boolean,
		hidden:Boolean,
		index:Number
	})
	const data = reactive({subComponent:{}})
	const init = function(){
		data.subComponent = markRaw(defineAsyncComponent({
			loader: () => import('../applications/' + setting.page + '.vue'),
			loadingComponent: loadingComponent,
			errorComponent: errorComponent,
			delay: 2000
		}));
	}
	init();
	onBeforeMount(() => {
		
	})
	onMounted(() => {
	})
	const onClose = function(){
		//console.log("=====>close");
		$store.dispatch('core/closeApplication',setting.id)
	}
</script>
<style lang="less">

.npad-application-container {
	position: fixed;
	top: 0%;
	left: 0%;
	width: 100%;
	height: 100%;
	z-index: 999;
	background-color:white;
}
.npad-application-header{
	width: 100%;
	height: 40px;
	display: flex;
	background-color: #e0e0e0;
	border-radius: 4px 4px 0 0;
	border-top: 1px solid #d0d0d0;
	border-left: 1px solid #d0d0d0;
	border-right: 1px solid #d0d0d0;

}
.npad-application-header-control {
	flex-wrap: nowrap;
	width:5%;
	padding: 0 5px;
}
.npad-application-header-icon {
	height: 30px;
	width: 30px;
	margin: 5px 5px;
	background-size: cover;
}
.npad-application-header-title{
	flex-wrap: nowrap;
	width:95%;
	height: 100%;
	text-align: center;
	min-height: 20px;
	line-height: 40px;
	font-size: 20px;
}

.npad-application-control-close {
	background-image: url("@/assets/icon/close.png");
	background-position: center center;
	background-repeat:no-repeat;
	height: 40px;
	width: 40px;
	margin: 0 auto;
	background-size: 30px;
}
.npad-application-body {
	background: #f9f9f9;
	right: 0;
	bottom: 0;
	left: 0;
	position: absolute;
	top: 40px;
	width: 100%;
}
</style>
